home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: aschen@ix.netcom.com (Sean Aschen)
- Newsgroups: comp.lang.c++
- Subject: Re: Why use private class members instead of protected?
- Date: Thu, 11 Jan 1996 07:08:47 GMT
- Organization: Netcom
- Message-ID: <30f4b64e.624277@nntp.ix.netcom.com>
- References: <30F4AB49.6ABB@sierra.net>
- NNTP-Posting-Host: ix-dby-ct2-16.ix.netcom.com
- X-NETCOM-Date: Wed Jan 10 11:20:24 PM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- On Wed, 10 Jan 1996 22:16:41 -0800, TGColwell <snowbull@sierra.net>
- wrote:
-
- >I'm relatively new to c++. I have one quick question: If child
- >classes can only access protected members of the parent class,
- >why make any members of any class private? Wouldn't it be
- >better to make members of the parent class protected so that the
- >class is alway "inheritance ready"?
- >
- >Thanks in advance,
- >
- >-Tyler
- Depends on who will be using your class. It is better to create a
- function/method which manipulates the data member of the parent class.
- This way the parent class knows exactly what to expect. Otherwise, a
- derived class may alter data members in a way which you didn't account
- for when creating the base class, causing problems. The whole purpose
- for object-oriented data stuctures is data-encapsulation. Using
- protected data members violates that encapsulation. Actually, most of
- my classes don't go any further than my own system, so I use protected
- all the time: makes for less typing.
-
- Hope that made sense...
-
-
-